package com.aj.http.response;

import java.util.ArrayList;
import java.util.List;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import com.aj.databases.entry.CmtInfo;
import com.aj.databases.entry.DigUserInfo;
import com.aj.databases.entry.LookPhotoInfo;
import com.aj.databases.entry.PhotoDateInfo;
import com.aj.databases.entry.PhotoInfo;

public class LookZonePhotoResponse extends BaseRespond {

	private LookPhotoInfo lookPhotoInfo;

	public LookZonePhotoResponse(JSONObject json) {
		super(json);
		if (!common.getResult().isNull("list")) {
			try {
				lookPhotoInfo = new LookPhotoInfo();
				if (!common.getResult().isNull("totalResults")) {
					lookPhotoInfo.setTotalResults(common.getResult().getInt(
							"totalResults"));
				}
				List<PhotoDateInfo> photoDateInfoList = new ArrayList<PhotoDateInfo>();
				JSONArray jsonArray = common.getResult().getJSONArray("list");
				for (int i = 0; i < jsonArray.length(); i++) {
					PhotoDateInfo photoDateInfo = new PhotoDateInfo();
					if (!jsonArray.getJSONObject(i).isNull("date")) {
						photoDateInfo.setDate(jsonArray.getJSONObject(i)
								.getString("date"));
					}
					JSONArray photoJSONArray = jsonArray.getJSONObject(i)
							.getJSONArray("photoPreDayList");
					List<PhotoInfo> photoInfoList = new ArrayList<PhotoInfo>();
					for (int j = 0; j < photoJSONArray.length(); j++) {
						JSONObject tempJSONObject = photoJSONArray
								.getJSONObject(j);
						PhotoInfo photoInfo = new PhotoInfo();
						if (!tempJSONObject.isNull("descript")) {
							photoInfo.setDescript(tempJSONObject
									.getString("descript"));
						}
						if (!tempJSONObject.isNull("photoId")) {
							photoInfo.setPhotoId(tempJSONObject
									.getString("photoId"));
						}
						if (!tempJSONObject.isNull("dig_num")) {
							photoInfo.setDig_num(tempJSONObject
									.getString("dig_num"));
						}
						if (!tempJSONObject.isNull("hadDig")) {
							photoInfo.setHadDig(tempJSONObject
									.getString("hadDig"));
						}
						if (!tempJSONObject.isNull("photo")) {
							photoInfo.setPhoto(tempJSONObject
									.getString("photo"));
						}
						if (!tempJSONObject.isNull("photoUrl")) {
							photoInfo.setPhoto(tempJSONObject
									.getString("photoUrl"));
						}
						if (!tempJSONObject.isNull("isPrivate")) {
							photoInfo.setIsPrivate(tempJSONObject
									.getString("isPrivate"));
						}
						if (!tempJSONObject.isNull("digList")) {
							JSONArray hadDigArray = tempJSONObject
									.getJSONArray("digList");
							List<DigUserInfo> digUserInfoList = new ArrayList<DigUserInfo>();
							for (int x = 0; x < hadDigArray.length(); x++) {
								DigUserInfo digUserInfo = new DigUserInfo();
								digUserInfo.setDig_user_id(hadDigArray
										.getJSONObject(x).getString(
												"dig_user_id"));
								digUserInfo.setDig_user_nick(hadDigArray
										.getJSONObject(x).getString(
												"dig_user_nick"));
								digUserInfo.setDig_user_photo(hadDigArray
										.getJSONObject(x).getString(
												"dig_user_photo"));
								digUserInfoList.add(digUserInfo);
							}
							photoInfo.setDigUserInfoList(digUserInfoList);
						}
						if (!tempJSONObject.isNull("cmtList")) {
							JSONArray cmtDigArray = tempJSONObject
									.getJSONArray("cmtList");
							List<CmtInfo> cmtInfoList = new ArrayList<CmtInfo>();
							for (int x = 0; x < cmtDigArray.length(); x++) {
								CmtInfo cmtInfo = new CmtInfo();
								cmtInfo.setCmtContent(cmtDigArray
										.getJSONObject(x).getString(
												"cmtContent"));
								if (!cmtDigArray.getJSONObject(x).isNull(
										"cmtUserCallName")) {
									cmtInfo.setCmtUserCallName(cmtDigArray
											.getJSONObject(x).getString(
													"cmtUserCallName"));
								}
								if (!cmtDigArray.getJSONObject(x).isNull(
										"commonId")) {
									cmtInfo.setCommonId(""
											+ cmtDigArray.getJSONObject(x)
													.getInt("commonId"));
								}
								if (!cmtDigArray.getJSONObject(x).isNull(
										"commentId")) {
									cmtInfo.setCommonId(""
											+ cmtDigArray.getJSONObject(x)
													.getInt("commentId"));
								}

								cmtInfo.setIsReply(cmtDigArray.getJSONObject(x)
										.getString("isReply"));
								if (!cmtDigArray.getJSONObject(x).isNull(
										"replyUserId")) {
									cmtInfo.setReplyUserId(cmtDigArray
											.getJSONObject(x).getString(
													"replyUserId"));
								}

								if (!cmtDigArray.getJSONObject(x).isNull(
										"replyUserNickName")) {
									cmtInfo.setReplyUserNickName(cmtDigArray
											.getJSONObject(x).getString(
													"replyUserNickName"));
								}
								if (!cmtDigArray.getJSONObject(x).isNull(
										"cmtUserId")) {
									cmtInfo.setCmtUserId(cmtDigArray
											.getJSONObject(x).getString(
													"cmtUserId"));
								}
								if (!cmtDigArray.getJSONObject(x).isNull(
										"replyUserCallName")) {
									cmtInfo.setReplyUserCallName(cmtDigArray
											.getJSONObject(x).getString(
													"replyUserCallName"));
								}
								if (!cmtDigArray.getJSONObject(x).isNull(
										"cmtUserNickName")) {
									cmtInfo.setCmtUserNickName(cmtDigArray
											.getJSONObject(x).getString(
													"cmtUserNickName"));
								}
								cmtInfoList.add(cmtInfo);
							}
							photoInfo.setCmtInfoList(cmtInfoList);
						}
						photoInfoList.add(photoInfo);
					}
					photoDateInfo.setPhotoInfoList(photoInfoList);
					photoDateInfoList.add(photoDateInfo);
				}
				lookPhotoInfo.setPhotoDateInfoList(photoDateInfoList);
			} catch (JSONException e) {
				e.printStackTrace();
			}

		}
	}

	public LookPhotoInfo getLookPhotoInfo() {
		return lookPhotoInfo;
	}

	public void setLookPhotoInfo(LookPhotoInfo lookPhotoInfo) {
		this.lookPhotoInfo = lookPhotoInfo;
	}

}
